<?php
/**
 * Created by PhpStorm.
 * User: pc
 * Date: 2018/12/13
 * Time: 15:28
 */

namespace app\admin\model;

use think\Db;
use think\Model;

class Role extends Model
{
    /**
     * 获取当前用户下的角色列表(不包含当前用户所属角色)
     * @param array $data SESSION
     * @return false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getRoles($data = [])
    {
        if ($data['user_id'] == 1) {//总公司
            $where['flag'] = 1;
            $where['creater_id'] = $data['user_id'];
            $where['company_id'] = $data['company_id'];
            $where['id'] = ['neq', $data['role_id']];
        } else {
            $where['creater_id'] = $data['user_id'];
            $where['id'] = ['neq', $data['role_id']];
        }
        $where['flag'] = 1;
        $where['status'] = 1;
        $role = Db::name('auth_group')
            ->where($where)
            ->order('sort asc')
            ->select();
        return $role;
    }
}